package tony.com.test;

import android.os.Bundle;
import android.os.PersistableBundle;
import android.util.Log;

import com.amap.api.location.AMapLocation;
import com.amap.api.maps2d.AMap;
import com.amap.api.maps2d.LocationSource;
import com.amap.api.maps2d.MapView;
import com.amap.api.maps2d.model.BitmapDescriptorFactory;
import com.amap.api.maps2d.model.MyLocationStyle;

import tony.com.xframe.acitivity.BaseActivity;
import tony.com.xframe.position.gdposition.GDPosition;

;

/**
 * Created by Tony on 2016-01-05.
 */
public class GDPositionActivity extends BaseActivity {
    //声明变量
    private MapView mapView;
    private AMap aMap;
    GDPosition gdPosition = GDPosition.getInstance();

    @Override
    public int getLayoutId() {

        Log.e("info", "getLayoutId");
        return R.layout.activity_gd_position;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.e("info", "oncreate");
//        setContentView(R.layout.activity_gd_position);
        mapView = (MapView) findViewById(R.id.map);
        mapView.onCreate(savedInstanceState);// 必须要写
        aMap = mapView.getMap();
        initAMap();
    }

    @Override
    public void onSaveInstanceState(Bundle outState, PersistableBundle outPersistentState) {
        super.onSaveInstanceState(outState, outPersistentState);
        mapView.onSaveInstanceState(outState);
    }

    @Override
    public void initWidge() {


        gdPosition.getPosition(new GDPosition.GDPositionListener() {
            @Override
            public AMapLocation getPositionResult(AMapLocation aMapLocation) {
                Log.d("GDPositionActivity", "aMapLocation:" + aMapLocation);

                return aMapLocation;
            }
        });

    }

    @Override
    public void widgeClick(int viewId) {

    }

    @Override
    protected void onResume() {
        super.onResume();
        mapView.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
        mapView.onPause();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mapView.onDestroy();
    }

    private void initAMap() {
        aMap.setMapType(AMap.MAP_TYPE_NORMAL);//矢量地图
        aMap.getUiSettings().setMyLocationButtonEnabled(true);//设置默认定位按钮显示
        aMap.setMyLocationEnabled(true);
        MyLocationStyle myLocationStyle = new MyLocationStyle();
        myLocationStyle.myLocationIcon(BitmapDescriptorFactory.
                fromResource(R.mipmap.ic_launcher));//  设置定位的图像
        aMap.setMyLocationStyle(myLocationStyle);

        gdPosition.getPosition(new GDPosition.GDPositionListener() {
            @Override
            public AMapLocation getPositionResult(final AMapLocation aMapLocation) {
                aMap.setLocationSource(new LocationSource() {
                    @Override
                    public void activate(OnLocationChangedListener onLocationChangedListener) {
                        onLocationChangedListener.onLocationChanged(aMapLocation);
                    }

                    @Override
                    public void deactivate() {

                    }
                });
                return null;
            }
        });


    }


}
